package com.yhyl.nursing.service.impl;

import java.util.List;
import com.yhyl.common.utils.DateUtils;
import com.yhyl.nursing.domain.NursingPlan;
import com.yhyl.nursing.vo.nursingProjectvo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import com.yhyl.nursing.mapper.NursingProjectMapper;
import com.yhyl.nursing.domain.NursingProject;
import com.yhyl.nursing.service.INursingProjectService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.Arrays;

/**
 * 护理项目Service业务层处理
 *
 * @author ruoyi
 * @date 2025-05-12
 */
@Service
public class NursingProjectServiceImpl extends ServiceImpl<NursingProjectMapper, NursingProject> implements INursingProjectService
{
    @Autowired
    private NursingProjectMapper nursingProjectMapper;

    @Autowired
    private RedisTemplate<Object,Object> redisTemplate;
    //定义一个删除缓存的方法
    private void deleteCache(){
        redisTemplate.delete(Project_KEY);
    }
    private static final String Project_KEY = "nursingproject:all";

    /**
     * 查询护理项目
     *
     * @param id 护理项目主键
     * @return 护理项目
     */
    @Override
    public NursingProject selectNursingProjectById(Long id)
    {
        return getById(id);
    }

    /**
     * 查询护理项目列表
     *
     * @param nursingProject 护理项目
     * @return 护理项目
     */
    @Override
    public List<NursingProject> selectNursingProjectList(NursingProject nursingProject)
    {
        return nursingProjectMapper.selectNursingProjectList(nursingProject);
    }

    /**
     * 新增护理项目
     *
     * @param nursingProject 护理项目
     * @return 结果
     */
    @Override
    public int insertNursingProject(NursingProject nursingProject)
    {

        boolean  flag = save(nursingProject);
        deleteCache();
        return flag ? 1 : 0;
    }

    /**
     * 修改护理项目
     *
     * @param nursingProject 护理项目
     * @return 结果
     */
    @Override
    public int updateNursingProject(NursingProject nursingProject)
    {
        boolean  flag = updateById(nursingProject);
        deleteCache();
        return flag ? 1 : 0;
    }

    /**
     * 批量删除护理项目
     *
     * @param ids 需要删除的护理项目主键
     * @return 结果
     */
    @Override
    public int deleteNursingProjectByIds(Long[] ids)
    {
        boolean  flag = removeByIds(Arrays.asList(ids));
        deleteCache();
        return flag ? 1 : 0;

    }

    /**
     * 删除护理项目信息
     *
     * @param id 护理项目主键
     * @return 结果
     */
    @Override
    public int deleteNursingProjectById(Long id)
    {
        boolean  flag = removeById(id);
        deleteCache();
        return flag ? 1 : 0;
    }

    @Override
    public List<nursingProjectvo> listAll() {
        List<nursingProjectvo> list = (List<nursingProjectvo>)  redisTemplate.opsForValue().get(Project_KEY);
        if(list != null && list.size() > 0)
        {
            return list;
        }
        list = nursingProjectMapper.listAll();
        redisTemplate.opsForValue().set(Project_KEY,list);
        return list;
    }
}
